package com.example.fmgidsprototype;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.fmgidsprototype.model.Category;

public class CatsAdapter extends ArrayAdapter<String>{
	
	private Context ctx;

	public CatsAdapter(Context context, List<String> catNames) {
		super(context, R.layout.fmb_spinner_container, catNames);
		this.ctx = context;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = convertView;
		String catName = this.getItem(position);
		LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		rowView = inflater.inflate(R.layout.fmb_spinner_container, parent, false);
		TextView catLabel = (TextView)rowView.findViewById(R.id.catlist_label);
		ImageView catImage = (ImageView)rowView.findViewById(R.id.catlist_img);
		String imageName = Util.CAT_ICONS.get(catName.toLowerCase());
		catLabel.setText(catName);
		if(!catName.equals("All Venues")){
			catImage.setImageResource(ctx.getResources().getIdentifier(
					Util.stripExtension(imageName), "drawable", ctx.getPackageName()));
		}
		return rowView;
	}

}
